package com.ruoyi.food.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.food.object.TRedBlack;
/**
 * 食安红黑榜mapper
 * @author mengcc
 *
 */
@Mapper
public interface TRedBlackMapper extends BaseMapper<TRedBlack>{
	
	public static String sql="SELECT b.LIST_ID,b.ENTERPRISE_NAME,b.SHOP_SIGN,b.ADDRESS,b.EVAL_TIME,b.LIST_TYPE,b.IS_VALID from t_red_black b";
	
	@Select({"<script>",
        sql,
        "WHERE 1=1 and IS_VALID=1",
        "<when test='enterpriseName != \"\" and enterpriseName !=null'>",
        "AND b.ENTERPRISE_NAME like concat('%', #{enterpriseName}, '%')",
        "</when>",
        "<when test='shopSign != \"\" and shopSign !=null'>",
        "AND b.SHOP_SIGN like concat('%', #{shopSign}, '%')",
        "</when>",
        "<when test='listType != 3'>",
        "AND b.LIST_TYPE=#{listType}",
        "</when>",
        "</script>"})
	public List<TRedBlack> selectRedBlack(TRedBlack tRedBlack);
	
	@Insert("insert into t_red_black(ENTERPRISE_NAME,SHOP_SIGN,ADDRESS,EVAL_TIME,LIST_TYPE,IS_VALID) "
			+ "VALUES(#{enterpriseName},#{shopSign},#{address},#{evalTime},#{listType},1)")
	public void insertRedBlack(TRedBlack tRedBlack);
	
	@Select("SELECT *from t_red_black where list_id=#{listId}")
	public TRedBlack selectRedBlackById(long listId);
	
	@Update("update t_red_black set ENTERPRISE_NAME=#{enterpriseName},SHOP_SIGN=#{shopSign},ADDRESS=#{address},LIST_TYPE=#{listType},EVAL_TIME=#{evalTime} where list_id=#{listId}")
	public int updateRedBlack(TRedBlack tRedBlack);
	
	/**
	 * 逻辑删除
	 * @param listId
	 */
	@Update("update t_red_black set IS_VALID=0 where list_id=#{listId}")
	public void deleteRedBlack(long listId);
	
	@Select(sql+" WHERE IS_VALID=1")
	public List<TRedBlack> selectAllRedBlack();

}
